use serde::{Deserialize, Serialize};
use std::net::IpAddr;

pub type RecordId = u32;
pub type Port = u16;
pub type Timestamp = i64;
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone, Copy)]
pub struct RecordTypeId(pub u32);

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RecordEntry {
    pub timestamp: Timestamp,
    pub type_id: RecordTypeId,
    pub ip_addr: Vec<IpAddr>,
    pub port: Vec<Port>,
    pub str: Vec<String>,
    pub num: Vec<u32>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RecordItemEntry {
    pub name: String,
    pub display_name: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RecordIpAddrEntry {
    pub base: RecordItemEntry,
    pub geoip: bool,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RecordTypeEntry {
    pub name: String,
    pub display_name: String,
    pub ip_addr: Vec<RecordIpAddrEntry>,
    pub port: Vec<RecordItemEntry>,
    pub str: Vec<RecordItemEntry>,
    pub num: Vec<RecordItemEntry>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RecordType {
    pub id: RecordTypeId,
    #[serde(flatten)]
    pub entry: RecordTypeEntry,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Record {
    pub id: RecordId,
    #[serde(flatten)]
    pub entry: RecordEntry,
}
